#Boa:Dialog:Dialog1

import wx
import wx.richtext
import wx.stc
import consultasBD
import utiles

def create(parent):
    return Dialog1(parent)

[wxID_DIALOG1, wxID_DIALOG1ACEPTAR, wxID_DIALOG1RICHTEXTCTRL1, 
 wxID_DIALOG1STATICLINE1, wxID_DIALOG1STATICTEXT1, wxID_DIALOG1STATICTEXT10, 
 wxID_DIALOG1STATICTEXT11, wxID_DIALOG1STATICTEXT12, wxID_DIALOG1STATICTEXT13, 
 wxID_DIALOG1STATICTEXT2, wxID_DIALOG1STATICTEXT3, wxID_DIALOG1STATICTEXT4, 
 wxID_DIALOG1STATICTEXT5, wxID_DIALOG1STATICTEXT6, wxID_DIALOG1STATICTEXT7, 
 wxID_DIALOG1STATICTEXT8, wxID_DIALOG1STATICTEXT9, wxID_DIALOG1TEXTCTRL1, 
 wxID_DIALOG1TEXTCTRL2, 
] = [wx.NewId() for _init_ctrls in range(19)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(409, 181), size=wx.Size(491, 293),
              style=wx.DEFAULT_DIALOG_STYLE, title='Descripcion de pagos')
        self.SetClientSize(wx.Size(483, 266))

        self.staticText1 = wx.StaticText(id=wxID_DIALOG1STATICTEXT1,
              label='Forma de pago', name='staticText1', parent=self,
              pos=wx.Point(16, 16), size=wx.Size(72, 13), style=0)

        self.staticText2 = wx.StaticText(id=wxID_DIALOG1STATICTEXT2, label='*',
              name='staticText2', parent=self, pos=wx.Point(120, 16),
              size=wx.Size(40, 13), style=0)

        self.staticText3 = wx.StaticText(id=wxID_DIALOG1STATICTEXT3,
              label='Descripcion', name='staticText3', parent=self,
              pos=wx.Point(168, 16), size=wx.Size(54, 13), style=0)

        self.staticText4 = wx.StaticText(id=wxID_DIALOG1STATICTEXT4, label='*',
              name='staticText4', parent=self, pos=wx.Point(240, 16),
              size=wx.Size(224, 13), style=0)

        self.staticText5 = wx.StaticText(id=wxID_DIALOG1STATICTEXT5,
              label='Cantidad de cuotas', name='staticText5', parent=self,
              pos=wx.Point(16, 40), size=wx.Size(93, 13), style=0)

        self.staticText6 = wx.StaticText(id=wxID_DIALOG1STATICTEXT6, label='*',
              name='staticText6', parent=self, pos=wx.Point(120, 40),
              size=wx.Size(40, 13), style=0)

        self.staticText7 = wx.StaticText(id=wxID_DIALOG1STATICTEXT7,
              label='Monto cuota', name='staticText7', parent=self,
              pos=wx.Point(168, 40), size=wx.Size(60, 13), style=0)

        self.staticText8 = wx.StaticText(id=wxID_DIALOG1STATICTEXT8, label='*',
              name='staticText8', parent=self, pos=wx.Point(240, 40),
              size=wx.Size(72, 13), style=0)

        self.staticText9 = wx.StaticText(id=wxID_DIALOG1STATICTEXT9,
              label='Total linea', name='staticText9', parent=self,
              pos=wx.Point(320, 40), size=wx.Size(49, 13), style=0)

        self.staticText10 = wx.StaticText(id=wxID_DIALOG1STATICTEXT10,
              label='*', name='staticText10', parent=self, pos=wx.Point(384,
              40), size=wx.Size(80, 13), style=0)

        self.staticLine1 = wx.StaticLine(id=wxID_DIALOG1STATICLINE1,
              name='staticLine1', parent=self, pos=wx.Point(16, 72),
              size=wx.Size(448, 2), style=0)

        self.Aceptar = wx.Button(id=wxID_DIALOG1ACEPTAR, label='Aceptar',
              name='Aceptar', parent=self, pos=wx.Point(384, 232),
              size=wx.Size(75, 23), style=0)
        self.Aceptar.Bind(wx.EVT_BUTTON, self.OnAceptarButton,
              id=wxID_DIALOG1ACEPTAR)

        self.staticText11 = wx.StaticText(id=wxID_DIALOG1STATICTEXT11,
              label='Descripcion extendida', name='staticText11', parent=self,
              pos=wx.Point(16, 88), size=wx.Size(105, 13), style=0)

        self.richTextCtrl1 = wx.richtext.RichTextCtrl(id=wxID_DIALOG1RICHTEXTCTRL1,
              parent=self, pos=wx.Point(16, 112), size=wx.Size(448, 104),
              style=wx.richtext.RE_MULTILINE, value='')
        self.richTextCtrl1.SetLabel('text')

        self.staticText12 = wx.StaticText(id=wxID_DIALOG1STATICTEXT12,
              label='Lote', name='staticText12', parent=self, pos=wx.Point(16,
              224), size=wx.Size(21, 13), style=0)
        self.staticText12.Show(False)

        self.textCtrl1 = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRL1, name='textCtrl1',
              parent=self, pos=wx.Point(16, 240), size=wx.Size(48, 21), style=0,
              value='')
        self.textCtrl1.Show(False)

        self.textCtrl2 = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRL2, name='textCtrl2',
              parent=self, pos=wx.Point(64, 240), size=wx.Size(48, 21), style=0,
              value='')
        self.textCtrl2.Show(False)

        self.staticText13 = wx.StaticText(id=wxID_DIALOG1STATICTEXT13,
              label='Cupon', name='staticText13', parent=self, pos=wx.Point(64,
              224), size=wx.Size(31, 13), style=0)
        self.staticText13.Show(False)

    def __init__(self, parent, renglonPago):
        self._init_ctrls(parent)
        self.renglonPago = renglonPago
        self.ingresoDeDescripciones()
        formapago = self.staticText2.GetLabel()
        sql = "SELECT tipo FROM valores WHERE nombre='"+formapago+"'"
        tipo = consultasBD.ordenCrudaDict(sql)
        if tipo == None or tipo == () or len(tipo)==0:
            pass
        else:
            tipo = tipo[0]
        self.tipo = tipo["tipo"]
        if formapago in ["P","CH"] : self.tipo=1
        if self.tipo == 0:
            self.staticText12.Show(True)
            self.textCtrl1.Show(True)
            self.staticText13.Show(True)
            self.textCtrl2.Show(True)

    def OnAceptarButton(self, event):
        if self.tipo == 0:
            if self.textCtrl1.GetLabel()=="":
                utiles.mensaje(None,"Debe introducir el NUMERO DE LOTE")
                self.textCtrl1.SetLabel("")
                self.textCtrl1.SetFocus()
                return
            if self.textCtrl2.GetLabel()=="":
                utiles.mensaje(None,"Debe introducir el NUMERO DE CUPON")
                self.textCtrl2.SetLabel("")
                self.textCtrl2.SetFocus()
                return

            valor1 = 0
            try:
                valor1 = int(self.textCtrl1.GetLabel())
            except:
                utiles.mensaje(None,"NUMERO DE LOTE no valido")
                self.textCtrl1.SetLabel("")
                self.textCtrl1.SetFocus()
                return
            if valor1<0:
                utiles.mensaje(None,"NUMERO DE LOTE no valido")
                self.textCtrl1.SetLabel("")
                self.textCtrl1.SetFocus()
                return

            valor2 = 0
            try:
                valor2 = int(self.textCtrl2.GetLabel())
            except:
                utiles.mensaje(None,"NUMERO DE CUPON no valido")
                self.textCtrl1.SetLabel("")
                self.textCtrl1.SetFocus()
                return
            if valor2<0:
                utiles.mensaje(None,"NUMERO DE CUPON no valido")
                self.textCtrl1.SetLabel("")
                self.textCtrl1.SetFocus()
                return

            descripcion = self.richTextCtrl1.Value
            lote = self.textCtrl1.GetLabel()
            cupon = self.textCtrl2.GetLabel()
            self.renglonPago[1] = descripcion+" / "+lote+" / "+cupon
            self.descripcion = descripcion+" / "+lote+" / "+cupon
        else:
            descripcion = self.richTextCtrl1.Value
            self.renglonPago[1] = descripcion
            self.descripcion = descripcion
        self.Close()

    def ingresoDeDescripciones(self):
        self.staticText2.Label = self.renglonPago[0] #formapago
        self.staticText4.Label = self.renglonPago[1] #descripcion
        self.staticText6.Label = self.renglonPago[2] #cuotas
        self.staticText8.Label = self.renglonPago[3] #montocuota
        self.staticText10.Label = self.renglonPago[4] #totallinea
        self.richTextCtrl1.Value = self.renglonPago[1] + " "
        
    def getDescripcion(self):
        return self.descripcion
